package com.six.park.dao;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Delete;

import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Mapper
@Repository("mapper")
public interface ParkMapper {
	//登录
	@Select("select * from admin where username=#{uname} and password=#{pwd}")
	public Map login(Map map);

	//登录2
	@Select("select garageName from admin2 where admin=#{uname} and pwd=#{pwd}")
	public Map login2(Map map);

	//日志
	@Select("select * from temp_park")
	public List<Map> log();

	//日志
	@Select("select * from temp_park where garageName=#{garageName}")
	public List<Map> log2(Map map);

	//dt1------------------------------------------------------------------------------
	//空车位查询
	@Select("select Vehicle_id from dt1 where Vehicle_status=0 order by RAND() limit 1")
	public Map cheWeiSelect1(Map map);
	//车位修改  空———》已占
	@Update("update dt1 set Vehicle_status=1,Vehicle_number=#{carname},entry_time=#{str_date1} where Vehicle_id =#{Vehicle_id}")
	public int cheWeiUpdate1(Map map);
	//车牌查询车位和进入时间等信息
	@Select("select * from dt1 where Vehicle_number =#{carname}")
	public List<Map> cheWei1(Map map);
	//查询结算起始时间
	@Select("select entry_time from dt1 where Vehicle_number=#{carname}")
	public Map inTime1(Map map);
	//结算
	@Update("update dt1 set leave_time=#{str_date1},time_quantum=#{str},spend=#{sum} where Vehicle_number=#{carname}")
	public int jieSuan1(Map map);
	//查询出去的车的id，状态码，根据车牌查询
	@Select("select Vehicle_id,Vehicle_status from dt1 where Vehicle_number=#{carname}")
	public Map select1(Map map);
	//删除车位表里的车牌(车走车位状态码为零)
	@Delete("delete from dt1 where Vehicle_number=#{carname}")
	public int deleteCar1(Map map);
	//添加车位信息（id 状态码）
	@Insert("insert into dt1(Vehicle_id,Vehicle_status,Vehicle_number,entry_time,leave_time,time_quantum,spend) values(#{Vehicle_id},0,'','','','','')")
	public int insert1(Map map);

    //dt2------------------------------------------------------------------------------
    //空车位查询
    @Select("select Vehicle_id from dt2 where Vehicle_status=0 order by RAND() limit 1")
    public Map cheWeiSelect2(Map map);
    //车位修改  空———》已占
    @Update("update dt2 set Vehicle_status=1,Vehicle_number=#{carname},entry_time=#{str_date1} where Vehicle_id =#{Vehicle_id}")
    public int cheWeiUpdate2(Map map);
    //车牌查询车位和进入时间等信息
    @Select("select * from dt2 where Vehicle_number =#{carname}")
    public List<Map> cheWei2(Map map);
    //查询结算起始时间
    @Select("select entry_time from dt2 where Vehicle_number=#{carname}")
    public Map inTime2(Map map);
    //结算
    @Update("update dt2 set leave_time=#{str_date1},time_quantum=#{str},spend=#{sum} where Vehicle_number=#{carname}")
    public int jieSuan2(Map map);
    //查询出去的车的id，状态码，根据车牌查询
    @Select("select Vehicle_id,Vehicle_status from dt2 where Vehicle_number=#{carname}")
    public Map select2(Map map);
    //删除车位表里的车牌(车走车位状态码为零)
    @Delete("delete from dt2 where Vehicle_number=#{carname}")
    public int deleteCar2(Map map);
    //添加车位信息（id 状态码）
    @Insert("insert into dt2(Vehicle_id,Vehicle_status,Vehicle_number,entry_time,leave_time,time_quantum,spend) values(#{Vehicle_id},0,'','','','','')")
    public int insert2(Map map);

    //dt3------------------------------------------------------------------------------
    //空车位查询
    @Select("select Vehicle_id from dt3 where Vehicle_status=0 order by RAND() limit 1")
    public Map cheWeiSelect3(Map map);
    //车位修改  空———》已占
    @Update("update dt3 set Vehicle_status=1,Vehicle_number=#{carname},entry_time=#{str_date1} where Vehicle_id =#{Vehicle_id}")
    public int cheWeiUpdate3(Map map);
    //车牌查询车位和进入时间等信息
    @Select("select * from dt3 where Vehicle_number =#{carname}")
    public List<Map> cheWei3(Map map);
    //查询结算起始时间
    @Select("select entry_time from dt3 where Vehicle_number=#{carname}")
    public Map inTime3(Map map);
    //结算
    @Update("update dt3 set leave_time=#{str_date1},time_quantum=#{str},spend=#{sum} where Vehicle_number=#{carname}")
    public int jieSuan3(Map map);
    //查询出去的车的id，状态码，根据车牌查询
    @Select("select Vehicle_id,Vehicle_status from dt3 where Vehicle_number=#{carname}")
    public Map select3(Map map);
    //删除车位表里的车牌(车走车位状态码为零)
    @Delete("delete from dt3 where Vehicle_number=#{carname}")
    public int deleteCar3(Map map);
    //添加车位信息（id 状态码）
    @Insert("insert into dt3(Vehicle_id,Vehicle_status,Vehicle_number,entry_time,leave_time,time_quantum,spend) values(#{Vehicle_id},0,'','','','','')")
    public int insert3(Map map);

	//查询DT1车库中的车辆
	@Select("select * from dt1")
	public List<Map> dt1();

	//查询DT2车库中的车辆
	@Select("select * from dt2")
	public List<Map> dt2();

	//查询DT3车库中的车辆
	@Select("select * from dt3")
	public List<Map> dt3();

	//图表1
	@Select("SELECT count(garageName) FROM `temp_park` GROUP BY garageName")
	public List<String> tb1();

	//图表2
	@Select("SELECT SUM(spend) FROM temp_park GROUP BY garageName")
	public List<String> tb2();

	//图表3 4
	@Select("SELECT entry_time,leave_time FROM temp_park")
	public List<Map> tb3();

	//图表32 42
	@Select("SELECT entry_time,leave_time FROM temp_park where garageName=#{garageName}")
	public List<Map> tb32(Map map);

	//查询会员
	@Select("select * from vipuser")
	public List<Map> vuser();

	//查询历史
	@Select("select * from temp_park")
	public List<Map> history();

	//查询管理员
	@Select("select * from admin2")
	public List<Map> role();

	//查询全部停车数，全部收入
	@Select("select count(*),sum(spend) from temp_park")
	public Map numberall();

	//查询全部停车数，全部收入
	@Select("select count(*),sum(spend) from temp_park where garageName=#{garageName}")
	public Map numberall2(Map map);
}
